//
//  WJLoginRegisterViewController.m
//  BeDeJie
//
//  Created by jerry on 2017/1/28.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "WJLoginRegisterViewController.h"
#import "WJLoginRegisterView.h"
#import "WJThreeLoginView.h"

@interface WJLoginRegisterViewController ()
@property (weak, nonatomic) IBOutlet UIView *middleView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadCons;

@end

@implementation WJLoginRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置背景色
    self.view.backgroundColor = WJColor(206, 206, 206);
    
    /*
     屏幕适配
     1. 一个view从xib中加载，一般需要重新固定尺寸，一定重新设置一下。
     2. 在viewDidLoad中设置控件的frame不好，开发中一般在viewDidLayoutSubviews中布局子控件。
     */
     
    
    //创建登录的view
    WJLoginRegisterView *loginView = [WJLoginRegisterView loginView];
    //添加到中间的view
    [self.middleView addSubview:loginView];
    
    //创建注册的view
    WJLoginRegisterView *registerView = [WJLoginRegisterView registerView];
    //添加到中间的view
    [self.middleView addSubview:registerView];
    
    //创建第三方登录view
    WJThreeLoginView *threeLoginView = [WJThreeLoginView threeLoginView];
    //添加到底部的view
    [self.bottomView addSubview:threeLoginView];
}

//根据布局调整控件的尺寸
-(void) viewDidLayoutSubviews {
    //一定要先调用此方法
    [super viewDidLayoutSubviews];
    
    WJLoginRegisterView *loginView = self.middleView.subviews[0];
    loginView.frame = CGRectMake(0, 0, self.middleView.wj_width * 0.5, self.middleView.wj_height);
    
    WJLoginRegisterView *registerView = self.middleView.subviews[1];
    registerView.frame = CGRectMake(self.middleView.wj_width * 0.5, 0, self.middleView.wj_width * 0.5, self.middleView.wj_height);

    WJThreeLoginView *threeLoginView = self.bottomView.subviews[0];
    threeLoginView.frame = self.bottomView.bounds;
}

- (IBAction)close:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        WJLog(@"退出登录注册页面");
    }];
}

- (IBAction)switchLoginRegister:(UIButton *)sender {
    sender.selected = !sender.selected;
    
    // 平移中间view
    _leadCons.constant = _leadCons.constant == 0? -self.middleView.wj_width * 0.5:0;
    
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
    }];
}

@end
